
/*
*********************************
	  SF2D Engine
*********************************

	By Julian Williams
	August 8, 2010
**********************************

	Description:

		Path Finding Class that is
	used for Ai Navigation around
	the map
***********************************
*/

#ifndef _PATH_FINDER_H
#define _PATH_FINDER_H


#include <Box2D\Box2D.h>

#include <iostream>
using namespace std;


//Internal A* solver
//Developed by Lee Thomason
//from sourceforge
#include "micropather.h"
using namespace micropather;

#include "Dynamic_Array.h"

//#define GRID_SIZE 10.6666



struct GridNode
{

	b2Vec2 grid_position;
	b2Vec2 screen_position;

	bool has_tower;
};


//Enum list for passable results
enum Triggers
{
	OPEN = 0,
	CREEP_SPAWN,
	CREEP_EXIT,
	NOT_BUILDABLE,
	NOT_WALKABLE,
	NOT_BUILDABLE_OR_WALKABLE
};


class Path_Finder : public Graph
{
public:

	Path_Finder();
	~Path_Finder();

	MicroPather* pEngine;


	int SolvePath( int, int, int, int, vector<void*> &, float & );

	void Setup( int, int );
	//set current  map dimentions
	void SetGridWidth( int );
	void SetGridHeight( int );



	//convert game positions to pather nodes and vice versa
	void NodeToXY( void* node, int* x, int* y );
	void* XYToNode( int x, int y );

	//new functions to convert to pather nodes from grid nodes, and vice vesa
	GridNode NodeToGrid( void* node );
	void* GridToNode( GridNode& );


	//print out node info
	virtual void PrintStateInfo( void* node );


	//Set/Get the Dynamic Array
	void Set_Passable(int, int, int);
	int  Get_Passable(int, int);


//an array that defines what is walkable
	
	//int passable[100][100];





private:
	//Stuff for internal path calculation
	DynamicArray<int> passable;

	int PassableTest( int nx, int ny );

	virtual float LeastCostEstimate( void* nodeStart, void* nodeEnd ) ;
	virtual void AdjacentCost( void* node, std::vector< StateCost > *neighbors );

	int map_width;
	int map_height;
};

extern Path_Finder Pather;
#endif